import main

import MyClasses.MailerFactory
import MyClasses.MyMailer

from unittest import TestCase
from mock import patch, Mock

class MainTest(TestCase):

	@patch('MyClasses.MailerFactory.MailerFactory')
	@patch('MyClasses.MyMailer') 
	def run_mailers_test(self, my_mailer, factory):

		mc = my_mailer.return_value
		mc.search.return_value = True
		mc.output.return_value = True

		assert MyClasses.MailerFactory.MailerFactory is factory
		assert MyClasses.MyMailer is my_mailer
		
		factory.fetch_all.return_value = (my_mailer(), my_mailer(), my_mailer())

		main.run_mailers('one', 'two')

		factory.fetch_all.assert_called_once_with()

		mc.search.assert_called_with('one', 'two')

		self.assertEquals(mc.search.call_count, 3)
		self.assertEquals(mc.output.call_count, 3)

if __name__ == "__main__":
	unittest.main()